package com.partner.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.partner.domain.TestYear;
import com.partner.response.TestYearResponse;
import com.partner.util.DBUtil;

/**
 * 考试年份的dao
 * @author Jinshuan
 *
 */
public class TestYearDao {
	QueryRunner queryRunner_auto = new QueryRunner(DBUtil.getDataSource());
	QueryRunner queryRunner_self = new QueryRunner();
	
	//查询考研年份
	public TestYearResponse getAllTestYear(){
		String sql = "select * from test_time";
		TestYearResponse testYearResponse = new TestYearResponse();
		List<TestYear> years = new ArrayList<TestYear>();
		try {
			if(queryRunner_auto.query(sql, new BeanListHandler<TestYear>(TestYear.class))!=null){
				years = queryRunner_auto.query(sql, new BeanListHandler<TestYear>(TestYear.class));
				testYearResponse.setCode("2000");
			}
		} catch (SQLException e) {
			testYearResponse.setCode("400");
			testYearResponse.setDescription("查询年份错误");
		}
		testYearResponse.setYears(years);
		return testYearResponse;
	}
}
